package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.MatchOddsRecord;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.MatchOddsRecordService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 matchOddsRecordController
//@RestController //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /matchOddsRecordController
public class MatchOddsRecordController {
	@Resource
    MatchOddsRecordService matchOddsRecordService;
	@GetMapping("/MatchOddsRecords")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<MatchOddsRecord> getAllMatchOddsRecord() throws Exception{
    	System.out.println("查询全部比赛赔率记录");
    	return matchOddsRecordService.getAllMatchOddsRecords();
    }

    @DeleteMapping("/MatchOddsRecords/{morno}")
	@ResponseBody
    public DTO<MatchOddsRecord> deleteMatchOddsRecordByMorno(@RequestBody @PathVariable("morno") String morno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(morno+"删除比赛赔率记录");
    	return matchOddsRecordService.deleteMatchOddsRecordByMorno(morno);
    }

	@PostMapping("/MatchOddsRecords")
	@ResponseBody
	public DTO<MatchOddsRecord> addMatchOddsRecord(@RequestBody MatchOddsRecord matchOddsRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加比赛赔率记录");
		return matchOddsRecordService.addMatchOddsRecord(matchOddsRecord);
	}

	@PatchMapping("/MatchOddsRecords")
	@ResponseBody
	public DTO<MatchOddsRecord> updateMatchOddsRecordByMorno(@RequestBody MatchOddsRecord matchOddsRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改比赛赔率记录成功");
		System.out.println(matchOddsRecord);
		return matchOddsRecordService.updateMatchOddsRecordByMorno(matchOddsRecord);
	}
	@GetMapping("/MatchOddsRecords/{morno}")
	@ResponseBody
	public DTO<MatchOddsRecord> getMatchOddsRecordByMorno(@PathVariable("morno") String morno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询比赛赔率记录");
		return matchOddsRecordService.getMatchOddsRecordByMorno(morno);
	}
	@GetMapping("/MatchOddsRecords/pageInfo")
	@ResponseBody
	public DTO<MatchOddsRecord> getMatchOddsRecordByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{
		String cacheId = "MatchOddsRecordByPage" + pageInfo.getCurrPage();//自编redis每页数据缓存的key
		return pageInfo.getCurrPage() > 2 ? matchOddsRecordService.getMatchOddsRecordByPage(pageInfo) :
				matchOddsRecordService.getMatchOddsRecordByPage(pageInfo,cacheId);
	}
//	@RequestMapping("/selectMatchOddsRecordWithorderAndUser/{morno}")
//	@ResponseBody
//	public DTO<MatchOddsRecord> selectMatchOddsRecordWithorderAndUser(@PathVariable("morno")String morno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
//		System.out.println("查询订单带上用户");
//		return matchOddsRecordService.selectMatchOddsRecordWithorderAndUser(morno);
//	}
}
